#ifndef S21_CONTAINER_LIST_CONST_ITERATOR_H_
#define S21_CONTAINER_LIST_CONST_ITERATOR_H_

#include "s21_list_node.h"

namespace s21 {

template <typename T>
class list;

template <typename T>
class ConstIterator {
 public:
  using iterator_category = std::bidirectional_iterator_tag;
  using value_type = T;
  using difference_type = std::ptrdiff_t;
  using pointer = T*;
  using reference = const T&;

  explicit ConstIterator(Node<T>* node) : node_(node) {}

  ConstIterator& operator++() {
    node_ = node_->next;
    return *this;
  }

  ConstIterator& operator++(int) {
    node_ = node_->next;
    return *this;
  }

  ConstIterator& operator--() {
    node_ = node_->prev;
    return *this;
  }

  ConstIterator& operator--(int) {
    node_ = node_->prev;
    return *this;
  }

  bool operator==(const ConstIterator& other) const noexcept {
    return node_ == other.node_;
  }

  bool operator!=(const ConstIterator& other) const noexcept {
    return node_ != other.node_;
  }

  reference operator*() const { return node_->value; }

 private:
  Node<T>* node_;
  friend class list<T>;
};
}  // namespace s21
#endif  // S21_CONTAINER_LIST_CONST_ITERATOR_H_